package vk 
{
	import asunit.framework.TestCase;
  import flash.events.Event;
  import flash.events.IOErrorEvent;	
  import flash.events.TimerEvent;
  import flash.utils.Timer;
  import vk.events.SongProviderEvent;
  
	/**
   * ...
   * @author Roman Marchenko
   */
  public class TestSongProvider extends TestCase 
  {
    private var provider: SongProvider;
    private var eventHandled: Boolean;
    private var event: Event;
    private var timer: Timer = new Timer(10000, 1);
    
    public function TestSongProvider(testMethod:String = null) 
    {
      super(testMethod);
    }
    
    protected override function setUp (): void
    {
      provider = new SongProvider(new Object);
    }
    
    protected override function tearDown (): void
    {
      provider = null;
    }

    public function testFindLatinSong(): void
    {
      var artist: String = "Nickelback";
      var title: String = "Photograph";
      
      var handler: Function = function (event: SongProviderEvent): void
      {
        assertEquals(artist, event.artist);
        assertEquals(title, event.title);
        assertNotNull(event.result);
        assertTrue(0 < event.result.length);
        assertNotNull(event.result[0].url);
      };
      
      provider.addEventListener(SongProviderEvent.SONG_FOUND,
                                addAsync(handler, 10000));
      provider.findSong(artist, title);
    }
    
    public function testFindCyrillicSong(): void
    {
      var handler: Function = function (event: SongProviderEvent): void
      {
        assertNotNull(event.result);
        assertTrue(0 < event.result.length);
      };
      
      provider.addEventListener(SongProviderEvent.SONG_FOUND,
                                addAsync(handler, 10000));
      provider.findSong("Блестящие", "Апельсиновая песня");
    }

    public function testFindNonexistantSong(): void
    {
      provider.addEventListener(SongProviderEvent.SONG_NOT_FOUND,
                                addAsync(null, 10000));
      provider.findSong("йцукенгшщзхъфывапролджэ", "ячсмитьбю");
    }
  }

}